<?php
Yii::import('zii.widgets.jui.CJuiWidget');

class SimpleCollapsiable extends CJuiWidget {
	
	public $expandText = 'Expand';
	
	public $collapseText = 'Collapse';
	
	public $controllerOptions = array();
	
	public $containerOptions = array();
	
	public function init(){
		$id=$this->getId();
		if(!isset($this->controllerOptions['id']))
			$this->controllerOptions['id'] = $id."_controller";
		
			
		if(!isset($this->containerOptions['id']))
			$this->containerOptions['id'] = $id."_container";
		echo CHtml::link($this->expandText,'#',$this->controllerOptions)."\n";
		echo CHtml::tag('hr')."\n";
		echo CHtml::openTag('div',$this->containerOptions)."\n";
	}
	public function run()
	{
		$id=$this->getId();
		
		echo CHtml::closeTag('div')."\n";
		$controller = $this->controllerOptions['id'];
		$container = $this->containerOptions['id'];
		$js =<<<EOD
			$('a#$controller').toggle(
	function(){
		$('#$container').hide();
		return false;
	},
	function(){
		$('#$container').show();
		return false;
	}
);
EOD;
		$cs = Yii::app()->getClientScript();
		$cs->registerScript(__CLASS__.'#'.$id, $js);
	}
}